#!/bin/sh
#
#	Clean the supplied SDCC library of stuff we don't want. This
#	IMHO beats forking the library or building a private copy.
#
#
CPU=$1
LIBZ80=$(../../Kernel/tools/findsdcc $CPU)
if [ ! -d $LIBZ80 ]; then
	THISSCRIPT=$(readlink -f "$0")
	echo "ERROR: Autodetected \$LIBZ80 is not a directory. Please edit $THISSCRIPT and set LIBZ80 manually" >&2
	exit 1
fi

cp $LIBZ80/$CPU.lib tmp.lib
#
#	Scrub the functions we don't want to inherit
#	Need to review setjmp and maybe a couple of others
#
#
sdar d tmp.lib putchar.rel heap.rel fstubs.rel errno.rel
sdar d tmp.lib rand.rel _calloc.rel _malloc.rel _realloc.rel _free.rel
sdar d tmp.lib malloc.rel calloc.rel free.rel realloc.rel
sdar d tmp.lib printf_large.rel puts.rel gets.rel assert.rel time.rel
sdar d tmp.lib tolower.rel toupper.rel _ltoa.rel _itoa.rel abs.rel atoi.rel
# Added in 3.7.0rc so we can't rely on it yet and must always use our own
sdar d tmp.lib strtoul.rel
mv tmp.lib sdcc$CPU.lib
